using System;
using System.Collections.Generic;
using DataStore.Domain;
using NHibernate;
using NHibernate.Linq;
using System.Linq;

namespace DataStore.Repositories
{
    public class PersonRepository : IRepository<Person>
    {
        readonly UnitOfWork _unitOfWork;

        public PersonRepository(UnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        public Person Get(object id)
        {
            throw new NotImplementedException();
        }

        public void Delete(Person entity)
        {
            ISession session = _unitOfWork.Session;
            session.Delete(entity);
        }

        public void DeleteAll()
        {
            throw new NotImplementedException();
        }

        public void Save(Person entity)
        {
            ISession session = _unitOfWork.Session;
            session.Save(entity);
        }

        public Person SaveOrUpdate(Person entity)
        {
            ISession session = _unitOfWork.Session;
            session.Save(entity);
            return entity;
        }

        public void Update(Person person)
        {
            ISession session = _unitOfWork.Session;
            session.Update(person);
            
        }

        IEnumerable<Person> IRepository<Person>.All
        {
            get
            {
                ISession session = _unitOfWork.Session;
                return session.Linq<Person>().ToList();
            }
        }

        public bool Exists(Person entity)
        {
            throw new NotImplementedException();
        }

        public bool IsEmpty
        {
            get { throw new NotImplementedException(); }
        }

        public int Count(Person entity)
        {
            throw new NotImplementedException();
        }

        public int CountAll()
        {
            throw new NotImplementedException();
        }

    }
}